/**************************************************************************************
 *
 * @(#) AuthController.java
 * @Package com.jgdt.jgdtkasannong_university_gene_backend.controller
 **************************************************************************************/
package com.jgdt.jgdtkasannong_university_gene_backend.controller.user;

import com.jgdt.jgdtkasannong_university_gene_backend.biz.user.AuthBiz;
import com.jgdt.jgdtkasannong_university_gene_backend.common.enums.BusinessCodeEnums;
import com.jgdt.jgdtkasannong_university_gene_backend.common.response.ResultVo;
import com.jgdt.jgdtkasannong_university_gene_backend.vo.user.LoginVo;
import com.jgdt.jgdtkasannong_university_gene_backend.vo.user.LogoutVo;
import com.jgdt.jgdtkasannong_university_gene_backend.vo.user.RegisterVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
 * @description: 用户认证控制器
 * @author: huangAn
 * @createDate: 2025/04/18
 */
@Tag(name = "用户模块",description = "用户模块")
@RestController
@RequestMapping("/api/user/auth")
public class AuthController {

    @Autowired
    private AuthBiz authBiz;

    @Operation(summary = "用户注册", description = "用户注册")
    @PostMapping("/register")
    public ResultVo<?> register(@RequestBody @Validated RegisterVo request) {
        authBiz.register(request);
        return ResultVo.success(BusinessCodeEnums.USER_REGISTER_SUC.getMsg());
    }

    @Operation(summary = "用户登录", description = "用户登录")
    @PostMapping("/login")
    public ResultVo<?> login(@RequestBody @Validated LoginVo request) {
        return ResultVo.success(authBiz.login(request));
    }

    @Operation(summary = "用户登出", description = "用户登出")
    @PostMapping("/logout")
    public ResultVo<?> logout(@RequestBody @Validated LogoutVo request) {
        authBiz.logout(request);
        return ResultVo.success();
    }
}



